package jnpf.service.impl;

import jnpf.entity.Whu_knowledgecollectionEntity;
import jnpf.entity.Whu_learningcollectionEntity;
import jnpf.mapper.Whu_learningcollectionMapper;
import jnpf.service.Whu_learningcollectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.util.RandomUtil;


import jnpf.model.whu_learningcollection.Whu_learningcollectionPagination;
import java.util.stream.Collectors;





import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.text.SimpleDateFormat;
import jnpf.util.*;
import java.util.*;

/**
 *
 * whu_learningcollection
 * 版本： V3.2.0
 * 版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * 作者： JNPF开发平台组
 * 日期： 2025-06-10
 */
@Service

public class Whu_learningcollectionServiceImpl extends ServiceImpl<Whu_learningcollectionMapper, Whu_learningcollectionEntity> implements Whu_learningcollectionService {

    @Autowired
    private UserProvider userProvider;






    @Override
    public List<Whu_learningcollectionEntity> getList(Whu_learningcollectionPagination whu_learningcollectionPagination){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
        int total=0;
                    QueryWrapper<Whu_learningcollectionEntity> whu_learningcollectionQueryWrapper=new QueryWrapper<>();
            int whu_learningcollectionNum =0;
			if(StringUtil.isNotEmpty(whu_learningcollectionPagination.getTodate())){
            whu_learningcollectionNum++;
            List<String> TodateList =  whu_learningcollectionPagination.getTodate();
            Long fir = Long.valueOf(TodateList.get(0));
            Long sec = Long.valueOf(TodateList.get(1));

                whu_learningcollectionQueryWrapper.lambda().ge(Whu_learningcollectionEntity::getTodate, new Date(fir))
            .le(Whu_learningcollectionEntity::getTodate, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

                    }

			if(StringUtil.isNotEmpty(whu_learningcollectionPagination.getType())){
            whu_learningcollectionNum++;
                whu_learningcollectionQueryWrapper.lambda().eq(Whu_learningcollectionEntity::getType,whu_learningcollectionPagination.getType());
                    }


			if(StringUtil.isNotEmpty(whu_learningcollectionPagination.getName())){
            whu_learningcollectionNum++;
            whu_learningcollectionQueryWrapper.lambda().like(Whu_learningcollectionEntity::getName,whu_learningcollectionPagination.getName());
                    }

            whu_learningcollectionQueryWrapper.lambda().eq(Whu_learningcollectionEntity::getUserid,userId);

        if(AllIdList.size()>0){
            whu_learningcollectionQueryWrapper.lambda().in(Whu_learningcollectionEntity::getId, AllIdList);
        }
        //排序
        if(StringUtil.isEmpty(whu_learningcollectionPagination.getSidx())){
        whu_learningcollectionQueryWrapper.lambda().orderByDesc(Whu_learningcollectionEntity::getTodate);
        }else{
        whu_learningcollectionQueryWrapper="asc".equals(whu_learningcollectionPagination.getSort().toLowerCase())?whu_learningcollectionQueryWrapper.orderByAsc(whu_learningcollectionPagination.getSidx()):whu_learningcollectionQueryWrapper.orderByDesc(whu_learningcollectionPagination.getSidx());
        }
        if((total>0 && AllIdList.size()>0) || total==0){
        Page<Whu_learningcollectionEntity> page=new Page<>(whu_learningcollectionPagination.getCurrentPage(), whu_learningcollectionPagination.getPageSize());
        IPage<Whu_learningcollectionEntity> userIPage=this.page(page, whu_learningcollectionQueryWrapper);
        return whu_learningcollectionPagination.setData(userIPage.getRecords(),userIPage.getTotal());
        }else{
            List<Whu_learningcollectionEntity> list = new ArrayList();
            return whu_learningcollectionPagination.setData(list, list.size());
        }
    }
    @Override
    public List<Whu_learningcollectionEntity> getTypeList(Whu_learningcollectionPagination whu_learningcollectionPagination,String dataType){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
		int total=0;
                    QueryWrapper<Whu_learningcollectionEntity> whu_learningcollectionQueryWrapper=new QueryWrapper<>();
            int whu_learningcollectionNum =0;
			if(StringUtil.isNotEmpty(whu_learningcollectionPagination.getTodate())){
            whu_learningcollectionNum++;
            List<String> TodateList =  whu_learningcollectionPagination.getTodate();
            Long fir = Long.valueOf(TodateList.get(0));
            Long sec = Long.valueOf(TodateList.get(1));

                whu_learningcollectionQueryWrapper.lambda().ge(Whu_learningcollectionEntity::getTodate, new Date(fir))
            .le(Whu_learningcollectionEntity::getTodate, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));

                    }

			if(StringUtil.isNotEmpty(whu_learningcollectionPagination.getType())){
            whu_learningcollectionNum++;
                whu_learningcollectionQueryWrapper.lambda().eq(Whu_learningcollectionEntity::getType,whu_learningcollectionPagination.getType());
                    }

			if(StringUtil.isNotEmpty(whu_learningcollectionPagination.getName())){
            whu_learningcollectionNum++;
            whu_learningcollectionQueryWrapper.lambda().like(Whu_learningcollectionEntity::getName,whu_learningcollectionPagination.getName());
                    }

		if(AllIdList.size()>0){
        whu_learningcollectionQueryWrapper.lambda().in(Whu_learningcollectionEntity::getId, AllIdList);
				}
        //排序
        if(StringUtil.isEmpty(whu_learningcollectionPagination.getSidx())){
        whu_learningcollectionQueryWrapper.lambda().orderByDesc(Whu_learningcollectionEntity::getTodate);
        }else{
        whu_learningcollectionQueryWrapper="asc".equals(whu_learningcollectionPagination.getSort().toLowerCase())?whu_learningcollectionQueryWrapper.orderByAsc(whu_learningcollectionPagination.getSidx()):whu_learningcollectionQueryWrapper.orderByDesc(whu_learningcollectionPagination.getSidx());
        }
        if("0".equals(dataType)){
            if((total>0 && AllIdList.size()>0) || total==0){
                Page<Whu_learningcollectionEntity> page=new Page<>(whu_learningcollectionPagination.getCurrentPage(), whu_learningcollectionPagination.getPageSize());
                IPage<Whu_learningcollectionEntity> userIPage=this.page(page, whu_learningcollectionQueryWrapper);
                return whu_learningcollectionPagination.setData(userIPage.getRecords(),userIPage.getTotal());
            }else{
                List<Whu_learningcollectionEntity> list = new ArrayList();
                return whu_learningcollectionPagination.setData(list, list.size());
            }
        }else{
            return this.list(whu_learningcollectionQueryWrapper);
        }
    }

    @Override
    public Whu_learningcollectionEntity getInfo(String id){
        QueryWrapper<Whu_learningcollectionEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(Whu_learningcollectionEntity::getId,id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(Whu_learningcollectionEntity entity){
        this.save(entity);
    }

    @Override
    public boolean update(String id, Whu_learningcollectionEntity entity){
        entity.setId(id);
        return this.updateById(entity);
    }
    @Override
    public void delete(Whu_learningcollectionEntity entity){
        if(entity!=null){
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法

}
